<?php

require_once 'db.class.php';

class Product extends Db
{
	public $tbname = 'products';

	public function getCates()
	{
		$this->sql = "select cates,catename,count(*) as total from ".$this->tbname." group by cates";
		return $this->dosql('_select');
	}

	public function getProductByCates($num=10)
	{
		$cates = $this->getCates();
		if($cates):
		foreach($cates as $val)
		{
			$this->sql = "select id,title,description from ".$this->tbname." where cates=".$val['cates']." order by addtime desc limit 0,".$num;
			if(in_array($val['cates'],array(6,7,8)))
			{
				$data[] = $this->dosql('_select');
			}
		}
		endif;
		return $data;
	}
}

?>